<template>
  <div class="container">
    <div class="tabs-lb">
      <!-- <span>服务编排</span> -->
      <button @click="addRow" class="btn_operation_add">
        <img src="~@/assets/img/grzx/add.png" alt />
        新增服务编排
      </button>
    </div>
    <div class="table">
      <el-table :data="tableData" style="min-height:550px">
        <el-table-column type="index" label="序号" width="60"></el-table-column>
        <el-table-column prop="fwmc" label="流程名称"></el-table-column>
        <el-table-column prop="fwbb" label="流程版本" width="100"></el-table-column>
        <el-table-column prop="fwzt" label="发布状态" width="100"></el-table-column>
        <el-table-column prop="address" label="操作" width="180">
          <template slot-scope="scope">
            <el-link type="primary" @click="sjRow(scope.row)">设计</el-link>
            <el-link type="danger" @click="deleteRow(scope.row)">删除</el-link>
            <el-link v-if="scope.row.fwzt === '未发布'" type="success" @click="qyRow(scope.row)">发布</el-link>
            <el-link v-else type="danger" @click="jyRow(scope.row)">禁用</el-link>
            <el-link v-if="scope.row.fwzt === '已发布'" type="primary" @click="csRow(scope.row)">测试</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        background
        @size-change="changePageSize"
        @current-change="changePageNum"
        :current-page="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <!-- 新增流程弹窗 -->
    <add-lc-dialog ref="addLcDialog" @updateTable="changePageNum(1)" />
  </div>
</template>
<script>
import bpfwglService from '@/api/bpfwgl'
import AddLcDialog from './dialogs/add-lc-dialog.vue'
export default {
  components: { AddLcDialog },
  data() {
    return {
      tableData: [],
      form: {
        filter: {
          cjrymc: '',
          fwbb: '',
          fwmc: '',
          fwzt: ''
        },
        orderBy: '',
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  mounted() {
    // 分页
    this.changePageNum(1)
  },
  methods: {
    /*
     * 获取流程列表
     */
    getLcList() {
      const params = { ...this.form }
      bpfwglService
        .queryBpfw(params)
        .then(res => {
          this.tableData = res.list
          this.total = res.total
        })
        .catch(err => {
          !err.isError &&
            this.$message({ type: 'warning', message: err.message })
        })
    },

    /*
     * 分页
     */
    changePageNum(val) {
      this.form.pageNum = val
      this.getLcList()
    },

    /*
     * 分页
     */
    changePageSize(val) {
      this.form.pageSize = val
      this.form.pageNum = 1
      this.getLcList()
    },

    /*
     * 新增流程
     */
    addRow() {
      this.$refs.addLcDialog?.openDialog()
    },

    /* 设计 */
    sjRow(row) {
      this.$router.push({
        path: '/fwbp',
        query: {
          cs: row.fwdybh
        }
      })
    },

    /*
     * 删除流程
     */
    deleteRow(row) {
      this.$confirm('确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const params = {
            fwdybh: row.fwdybh
          }
          bpfwglService
            .deleteBpfw(params)
            .then(res => {
              this.$message.success('删除成功')
              this.changePageNum(1)
            })
            .catch(err => {
              !err.isError &&
                this.$message({ type: 'warning', message: err.message })
            })
        })
        .catch(() => { })
    },

    /*
     * 发布流程-启用
     */
    qyRow(row) {
      const params = {
        fwdybh: row.fwdybh
      }
      bpfwglService
        .updateFwztqy(params)
        .then(res => {
          this.$message.success('启用成功')
          this.changePageNum(1)
        })
        .catch(err => {
          !err.isError &&
            this.$message({ type: 'warning', message: err.message })
        })
    },

    /*
     * 发布流程-禁用
     */
    jyRow(row) {
      const params = {
        fwdybh: row.fwdybh
      }
      bpfwglService
        .updateFwztjy(params)
        .then(res => {
          this.$message.success('禁用成功')
          this.changePageNum(1)
        })
        .catch(err => {
          !err.isError &&
            this.$message({ type: 'warning', message: err.message })
        })
    },
    // 点击测试按钮
    csRow(row) {
      this.$router.push({
        path: '/csts',
        query: {
          cs: row.fwdy
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  .table {
    width: 100%;
    background: #fff;
    margin-top: 20px;
    // padding-bottom: 20px;
  }
  .page {
    // position: absolute;
    // left: 40%;
    // bottom: 5%;
    margin-top: 20px;
    text-align: center;
  }
}
</style>
